package com.tecrun.common.utils;

import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;

/**
 * 读取json文件工具类
 */
public class JsonFileUtils {


    /**
     * 读取json文件
     * @param path 文件路径
     */
    public static String readJsonFromClassPath(String path) {
        ClassPathResource resource = new ClassPathResource(path);
        if (resource.exists()) {
            try (InputStream in =  resource.getInputStream();){
                return IOUtils.toString(in, Charset.forName("UTF-8"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

}
